//
//  OrderDetailsViewController.m
//  waiMai
//
//  Created by LONG on 16/4/19.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "OrderDetailsViewController.h"
#import "OrderDetailsTableViewCell.h"
#import "OrderStateViewController.h"
@interface OrderDetailsViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *myTableView;

@end

@implementation OrderDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"拉直肉夹馍";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"arrow"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    [self.navigationItem.leftBarButtonItem setTintColor:[UIColor whiteColor]];
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate =(id)self;
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self myTableView];
}
- (UITableView *)myTableView{
    if (nil == _myTableView){
        _myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-64)];
        _myTableView.backgroundColor = [UIColor whiteColor];
        _myTableView.delegate = self;
        _myTableView.dataSource = self;
        _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        [self.view addSubview:_myTableView];
    }
    return _myTableView;
}

#pragma mark tableView代理
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }else if(section == 1){
        return 6;
    }
    return 6;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell";
    OrderDetailsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    cell = [[OrderDetailsTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.section == 0) {
        [cell addSubview:cell.image];
        [cell addSubview:cell.gengduo];
        [cell.gengduo addTarget:self action:@selector(gengduoState) forControlEvents:UIControlEventTouchUpInside];
        cell.title.text = @"订单已经提交";
        [cell addSubview:cell.title];
        
        cell.viewlab.text = @"请等待商家确认";
        [cell addSubview:cell.viewlab];
        
        cell.timelab.text = @"10:00";
        [cell addSubview:cell.timelab];
        
    }else if (indexPath.section == 1){
        if (indexPath.row == 0) {
            cell.image.frame = CGRectMake(10, 5, 30, 30);
            [cell addSubview:cell.image];
            
            cell.title.frame = CGRectMake(50, 10, 200, 20);
            cell.title.text = @"拉直肉夹馍";
            cell.title.font = [UIFont systemFontOfSize:15];
            [cell addSubview:cell.title];
            
            cell.xian.centerY = 40;
            [cell addSubview:cell.xian];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        else if (indexPath.row == 2){
            cell.name.text = @"包装费";
            [cell addSubview:cell.name];
            cell.price.text = @"$20";
            [cell addSubview:cell.price];

        }else if (indexPath.row == 3){
            cell.name.text = @"配送费";
            [cell addSubview:cell.name];
            cell.price.text = @"$20";
            [cell addSubview:cell.price];

            cell.xian.centerY = 40;
            [cell addSubview:cell.xian];
        }
        else if (indexPath.row == 4){
            cell.name.text = @"总计";
            [cell addSubview:cell.name];
            cell.price.text = @"$20";
            [cell addSubview:cell.price];

            cell.xian.centerY = 40;
            [cell addSubview:cell.xian];
        }
        else if (indexPath.row == 5){
            [cell addSubview:cell.zailaiyidan];
        }else{
            cell.name.text = @"必做准备白吉馍";
            [cell addSubview:cell.name];
            
            cell.numer.text = @"x2";
            [cell addSubview:cell.numer];
            
            cell.price.text = @"$20";
            [cell addSubview:cell.price];

            cell.xian.centerY = 40;
            [cell addSubview:cell.xian];
        }

    }else if (indexPath.section == 2){
        NSArray *strarr = @[@"配送方式:",@"配送时间:",@"收货信息:",@"订单号:",@"支付方式:",@"备注信息:"];
        cell.name.text = strarr[indexPath.row];
        [cell addSubview:cell.name];
        
        cell.xian.centerY = 40;
        [cell addSubview:cell.xian];
    }
    
    
    return cell;
}

#pragma mark delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 70;
    }else if (indexPath.section == 1){
        return 40;
    }
    return 40;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 15;
    }
    return 30;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    NSArray *arr= @[@"  订单详情",@"  其他信息"];
    UILabel *header = [[UILabel alloc]init];
    header.backgroundColor = UIColorFromRGB(0xefeff1);
    header.font = [UIFont systemFontOfSize:14];
    header.textColor = UIColorFromRGB(0x333333);
    if (section == 0) {
        header.frame = CGRectMake(0, 0, WIDTH, 10);
    }else{
        header.frame = CGRectMake(0, 0, WIDTH, 30);
        header.text = arr[section-1];

    }
    return header;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
}
- (void)gengduoState{
    OrderStateViewController *ovc = [[OrderStateViewController alloc]init];
    [self.navigationController pushViewController:ovc animated:YES];
}
-(void)back{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    CGFloat sectionHeaderHeight = 40;
    
    if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
        
        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
        
    } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
        
        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
        
    }
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    self.tabBarController.tabBar.translucent = YES;
    self.tabBarController.tabBar.hidden = YES;
    
}

@end
